package com.gdones.gpt.bus.mask.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.gdones.common.core.dto.MyPageBand;
import com.gdones.common.core.dto.MyPager;
import com.gdones.common.core.dto.MyResult;
import com.gdones.gpt.bus.mask.dto.GptMask;
import com.gdones.gpt.bus.mask.mapper.GptMaskMapper;
import com.gdones.gpt.bus.mask.service.IGptMaskService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gdones.gpt.bus.modes.dto.GptModes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author GaoJingBo
 * @since 2023-06-10
 */
@Service
public class GptMaskServiceImpl extends ServiceImpl<GptMaskMapper, GptMask> implements IGptMaskService {

    @Autowired
    private GptMaskMapper gptMaskMapper;

    @Override
    public MyResult mypage(GptMask dto, MyPageBand pageBand) {

        MyResult result = new MyResult();

        IPage<GptMask> pages = gptMaskMapper.pages(PageDTO.of(pageBand.getPage(), pageBand.getSize()), dto);

        // 根据分页的结果封装返回数据
        MyPager<GptMask> pager = new MyPager<>();
        pager.setTotal(pages.getTotal());
        pager.setPage(pageBand.getPage());
        pager.setPageSize(pageBand.getSize());
        pager.setRows(pages.getRecords());

        result.setData(pager);
        result.setMsg("查询成功！");

        return result;
    }

    @Override
    public MyResult mylist(GptMask dto) {

        MyResult result = new MyResult();

        List<GptMask> list = gptMaskMapper.myList(dto);

        result.setData(list);
        result.setMsg("查询成功！");

        return result;
    }

    @Override
    public MyResult getByID(String id) {

        MyResult result = new MyResult();

        GptMask byId = this.getById(id);

        if(byId!=null){
            result.setData(byId);
            result.setMsg("查询成功！");
        }else{
            result.setMsg("查询失败不存在！");
            result.setCode("9999");
        }

        return result;
    }

    @Override
    public MyResult add(GptMask dto) {

        MyResult result = new MyResult();

        boolean save = this.save(dto);
        if(save){
            result.setMsg("添加成功！");
        }else{
            result.setCode("9999");
            result.setMsg("添加失败！");
        }

        return result;
    }

    @Override
    public MyResult update(GptMask dto) {

        MyResult result = new MyResult();

        boolean save = this.updateById(dto);
        if(save){
            result.setMsg("修改成功！");
        }else{
            result.setCode("9999");
            result.setMsg("修改失败！");
        }

        return result;
    }

    @Override
    public MyResult deletes(String ids) {

        MyResult result = new MyResult();

        String[] split = ids.split(",");
        List<String> list = Arrays.asList(split);

        boolean b = this.removeBatchByIds(list);
        if(b){
            result.setMsg("删除成功！");
        }else{
            result.setCode("9999");
            result.setMsg("删除失败！");
        }

        return result;
    }
}
